<template>
	<view>
		<view class="van_top">
			<van-nav-bar title="退款详情" fixed left-arrow @click-left="onClickLeft" />
		</view>
		<view class="content">
			<view class="safe-area" :style="{ height: (statusBarHeight + 46) + 'px' }" style="width: 100%;"></view>
			<view class="inner">
				<view class="shop">
					<view class="item" v-for="(item,index) in orderList" :key="item.id">
						<view class="pic">
							<image :src="item.images" mode="aspectFill"></image>
						</view>
						<view class="info">
							<view class="title van-ellipsis	">
								{{ item.commodityName }}
							</view>
							<view class="sub_title">
								配送规格：{{ item.deliveryNorms }} {{ item.unit }} * {{ item.refundQuantity }}
							</view>
							<view class="sub_title">
								单价：￥{{ item.salePrice | parseMoney }}
							</view>
						</view>
						<view class="price">
							￥{{ item.refundAmount | parseMoney}}
						</view>
					</view>
					<view class="more" @click="showAllOrder" v-if="!showAll && orderList.length != allOrderList.length">
						展开({{allOrderList.length}}种商品) <van-icon name="arrow-down" />
					</view>
				</view>
				<view class="order">
					<view class="line">
						<text class="left">订单编号</text>
						<text class="right">{{ orderDetailObj.tradeNo }}</text>
					</view>
					<view class="line">
						<text class="left">退款单号</text>
						<text class="right">{{ orderDetailObj.refundNo }}</text>
					</view>
					<view class="line">
						<text class="left">申请时间</text>
						<text class="right">{{ orderDetailObj.createTime | parseTime }}</text>
					</view>
					<view class="line">
						<text class="left">退款金额</text>
						<text class="right">￥{{ orderDetailObj.refundMoney }}</text>
					</view>
				</view>
				<view class="order">
					<view class="line" v-if="orderDetailObj.channel">
						<text class="left">退款渠道</text>
						<text class="right" v-if="orderDetailObj.channel == 'ORIGINAL'">退回付款账户</text>
						<text class="right" v-else-if="orderDetailObj.channel == 'BALABCE'">退回到微信余额</text>
						<text class="right" v-else-if="orderDetailObj.channel == 'OTHER_BALANCE'">退到其他账户余额</text>
						<text class="right" v-else-if="orderDetailObj.channel == 'OTHER_BANKCARD'">退到其他银行卡</text>
					</view>
					<view class="line">
						<text class="left">退款原因</text>
						<text class="right">{{orderDetailObj.reason}}</text>
					</view>
					<view class="line">
						<text class="left">退款状态</text>
						<text class="right" v-if="orderDetailObj.refundStatus == 'SUCCESS'">退款成功</text>
						<text class="right" v-else-if="orderDetailObj.refundStatus == 'CLOSED'">退款关闭</text>
						<text class="right" v-else-if="orderDetailObj.refundStatus == 'PROCESSING'">退款处理中</text>
						<text class="right" v-else-if="orderDetailObj.refundStatus == 'ABNORMAL'">退款异常</text>
					</view>
					<view class="line" v-if="orderDetailObj.successTime">
						<text class="left">处理时间</text>
						<text class="right">{{ orderDetailObj.successTime | parseTime }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	import { reqReturnOrderDetails } from '@/apis/order.js';
	import app from '@/App.vue';
	export default {
		data() {
			return {
				id: '',
				statusBarHeight: app.globalData.statusBarHeight,
				allOrderList: [],
				orderList: [],
				showAll: false,
				orderDetailObj: {
					tradeNo: '',
					refundNo: '',
					createTime: '',
					refundMoney: 0,
					channel: '',
					reason: '',
					refundStatus: '',
					successTime: ''
				}
			};
		},
		onLoad(params) {
			this.id = params.id;
			if (this.id != '') {
				this.getOrderDetail();
			}
		},
		methods: {
			onClickLeft() {
				uni.navigateBack();
			},
			async getOrderDetail() {
				let res = await reqReturnOrderDetails({ id: this.id });
				if (res.code === 200) {
					this.allOrderList = res.data.refundsDetailsList;
					this.orderList = this.allOrderList.slice(0, 3);
					this.orderDetailObj = {
						tradeNo: res.data.tradeNo,
						refundNo: res.data.refundNo,
						createTime: res.data.createTime,
						refundMoney: res.data.refundMoney,
						channel: res.data.channel,
						reason: res.data.reason,
						refundStatus: res.data.refundStatus,
						successTime: res.data.successTime
					}
				}
			},
			showAllOrder() {
				this.showAll = true;
				this.orderList = this.allOrderList;
			},
		},
	}
</script>
<style>
	page {
		background: #f5f5f5;
	}
</style>
<style lang="scss" scoped>
	.content {
		.inner {
			padding: 24rpx;
			box-sizing: border-box;

			.shop {
				padding: 24rpx;
				background-color: #fff;
				border-radius: 24rpx;
				margin-bottom: 24rpx;

				.item {
					display: flex;
					margin-bottom: 20rpx;

					.pic {
						width: 148rpx;
						height: 148rpx;
						margin-right: 16rpx;
						border-radius: 10rpx;

						image {
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}
					}

					.info {
						width: 302rpx;

						.title {
							width: 100%;
							font-weight: 500;
							font-size: 28rpx;
							color: #333333;
							margin-bottom: 16rpx;
						}

						.sub_title {
							font-weight: 500;
							font-size: 24rpx;
							color: #808080;
							margin-bottom: 16rpx;
						}
					}

					.price {
						flex: 1;
						text-align: right;
						font-weight: 500;
						font-size: 40rpx;
						color: #FF4F30;
						align-self: flex-start;
					}

				}

				.more {
					width: 100%;
					text-align: center;
					font-weight: 500;
					font-size: 24rpx;
					color: #808080;
					margin-bottom: 24rpx;
				}

				.total {
					display: flex;
					width: 100%;
					height: 64rpx;
					border-top: 1px solid #f5f5f5;
					justify-content: space-between;
					align-items: center;
					font-weight: 500;
					font-size: 28rpx;
					color: #333333;
				}
			}

			.order {
				padding: 24rpx;
				background-color: #fff;
				border-radius: 24rpx;
				margin-bottom: 24rpx;

				.line {
					display: flex;
					justify-content: space-between;
					margin-bottom: 24rpx;

					&:nth-last-child(1) {
						margin-bottom: 0;
					}

					.left {
						font-weight: 500;
						font-size: 28rpx;
						color: #333333;
					}

					.right {
						font-weight: 500;
						font-size: 24rpx;
						color: #808080;
					}
				}
			}

		}
	}
</style>